package mobile.TheOldRepublic.web;

import com.explodingzombie.util.GeneralUtils;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.util.Log;

public class JavascriptTools {
	
	private WebViewWrapper wv;
	private Activity activity;
	
	public JavascriptTools(Activity activity, WebViewWrapper wv){
		this.activity = activity;
		this.wv = wv;
	}

	/**
	 * @deprecated Instead forced WebView to work correctly.
	 */
	public void open(String url){
		final String link = url;
		// TODO I want to look at cleansing this string before release. LP
		activity.runOnUiThread(new Runnable() {
			public void run() {
				wv.loadUrl(link);
			}
		});
	}
	
	public void displayMessage(String message){
		Log.d(getClass().getSimpleName(), "Log message: "+message);
		if(GeneralUtils.isEmpty(message)) return;
		
		final String msg = message;
		activity.runOnUiThread(new Runnable() {
			public void run() {
				AlertDialog.Builder builder = new AlertDialog.Builder(activity);
				builder.setIcon(android.R.drawable.ic_dialog_alert);
				builder.setTitle(msg);
				builder.setCancelable(true);
				builder.setNegativeButton("Ok", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int id) {
						dialog.cancel();
					}
				});
				final AlertDialog dialog = builder.create();
				dialog.show();
			}
		});
	}
	
}
